<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="dao.QueryReservations"%>
<%@page import="dao.Entity.Reservations"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="css/allcss.css" rel="stylesheet" type="text/css"/>
        <link rel="shortcut icon"  href="image/icon6.ico" type="image/x-icon" /> 
        <script src="./script/jquery.js" type="text/javascript"></script>
        <title>Manage</title>
        <style>
        </style>
    </head>
    <body>
        <div id="aside">
            <img id="icon" src="./image/icon6.png">
            <div id="p1">管理员界面</div>         
        </div>
        <div id="main">
            <div id="list"><div id="op1" class="options">全部预约</div><div  id="op2" class="options">未审核</div><div  id="op3" class="options">已审核</div>
                <div  id="op4" class="options">地点管理</div><div  id="op5" class="options">地点上新</div><div  id="op6" class="options">数据库管理</div>
                <div  id="op7" class="options">学生信用度</div><div  id="op8" class="options">申诉回复</div></div>
            <div id="content">
                <%
                    Reservations res = null;
                    String type = request.getParameter("type");
                    if (type == null) {
                        res = QueryReservations.getResult(-1, null);
                    } else {
                        res = QueryReservations.getResult(Integer.parseInt(type), null);
                    }
                    if (res != null) {
                        for (int i = 0; i < res.reservations.size(); i++) {
                            int st = res.reservations.get(i).AppointmentCheckStatus;
                            int no = res.reservations.get(i).AppointmentNumber;
                            String button = "<button  id='manage_change_button_number" + i + "'  class='manage_change_button'  onclick='add(event)' value='" + no + "'>审核</button>";
                            String color = "yellow";
                            switch (st) {
                                case 0:
                                    color = "red";
                                    break;
                                case 1:
                                    color = "green";
                                    break;
                                case 2:
                                    color = "yellow";
                                    break;
                                case 3:
                                    color = "cancel";
                                    button = "";
                            }
                            out.println("<div id='" + no + "' class='reservations'><div class='reservation'>预约号：[" + no
                                    + "] 学生号：[" + res.reservations.get(i).StudentAccount + "]  预约时间：[" + res.reservations.get(i).AppointmentTime
                                    + "]  地点：[" + res.reservations.get(i).PlacePosition + "]  时间号：[" + res.reservations.get(i).PlaceTimeNumber
                                    + "] </div><div class='status'> 审核状态：</div><img class='status_img' src='./image/" + color + ".png'/>"
                                    + button + "</div>");
                        }
                    }
                %>
            </div>
        </div>
        <script src="./script/button.js" type="text/javascript"></script>
        <script>
            const urlParams = new URLSearchParams(window.location.search);
            var type = urlParams.get('type');
            if (type === "2") {
                $("#op2").css("color", "#00aeec");
            } else if (type === "0") {
                $("#op3").css("color", "#00aeec");
            } else {
                $("#op1").css("color", "#00aeec");
            }
            function add(event) {
                var id = event.target.id;
                var no = event.target.value;
                window.location.href = "updateStatus.jsp?number=" + no;
            }
        </script>
    </body>
</html>
